package com.dilidili.mapper;

import com.domain.Fans;
import com.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @PackgeName: com.dilidili.mappers
 * @ClassName: UserMapper
 * @Author: 零
 * Date: 2022/4/3 20:33
 * project name: spring-cloud-mybilibli
 * @Version:
 * @Description:
 */
@Mapper
public interface UserMapper{
    /**
     * 根据手机号查询用户
     * @param userTel 用户手机号
     * @return 用户信息
     */
    @Select("select * from mybilibili.user where user.user_tel=#{userTel};")
    List<Map<String,Object>> query(@Param("userTel") String userTel);

    /**
     * 根据手机号查询数据
     * @param userTel
     * @return
     */
    @Select("select user_id as userId,user_password as userPassword,user_tel as userTel from mybilibili.user where user.user_tel=#{userTel};")
    User userPhone(@Param("userTel") String userTel);

    /**
     * 根据手机号修改密码
     * @param userTel 手机号
     * @param userPassword 密码
     * @return 返回结果
     */
    @Update("update mybilibili.user set user_password =#{userPassword}  where user.user_tel=#{userTel} ;")
    Integer amendPswd(@Param("userTel") String userTel,@Param("userPassword") String userPassword);

    /**
     * 查询用户关注的人数
     * @param userId 用户id
     * @return 返回结果
     */
    Integer  fansByUserId(@Param("userId") Integer userId);


    /**
     * 查询用户的粉丝数量
     * @param userId 用户id
     * @return
     */
    @Select("select count(f.fans_user_id) from mybilibili.user u left join mybilibili.fans f on u.user_id = f.fans_bigv_user_id where u.user_id = #{userId};")
    Integer beanByUserId(@Param("userId") Integer userId);

    /**
     * 用户注册SQL
     * @param user 用户对象
     * @return 数据结果
     */
    @Insert("insert into mybilibili.user (user_password, user_tel, user_nickname, user_createtime, user_exp, user_class, user_closetime, user_imgsrc, user_suggest, user_openid) values (#{userPassword},#{userTel},#{userNickname},#{userCreatetime},#{userExp},#{userClass},#{userClosetime},#{userImgsrc},#{userSuggest},#{userOpenid});")
    Integer saveUser(User user);


    /**
     * 用户修改信息SQL
     * @param user 用户对象
     * @return 响应结果
     */
    Integer modification(User user);

    /**
     * 查询用户昵称SQL接口
     * @param userNickname 用户昵称
     * @return 返回数据
     */
    List<Map<String,Object>> userGetUserNickname(@Param("userId") Integer userId,@Param("userNickname") String userNickname);


    /**
     * 查询用户信息
     * @param userId
     * @param userNickname
     * @return
     */
    List<Map>  queryFansParticulars(@Param("userId") Integer userId,@Param("userNickname") String userNickname);


    List<User> queryFansBeanParticulars(@Param("userId") Integer userId, @Param("userNickname") String userNickname);

    /**
     * 根据id查询用户信息
     * @param userId 用户id
     * @return
     */
    User findAll(@Param("userId") Integer userId);
}
